package com.smart.web.controller.system;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.smart.common.annotation.Log;
import com.smart.common.core.controller.BaseController;
import com.smart.common.core.domain.AjaxResult;
import com.smart.common.enums.BusinessType;
import com.smart.common.core.domain.R;
import com.smart.system.domain.Config;
import com.smart.system.service.IConfigService;
import com.smart.common.utils.poi.ExcelUtil;
import com.smart.common.core.page.TableDataInfo;

/**
 * 配置Controller
 * 
 * @author smart
 * @date 2024-12-10
 */
@RestController
@RequestMapping("/system/config")
@Api(tags = "作业配置")
public class ConfigController extends BaseController
{
    @Autowired
    private IConfigService configService;

    /**
     * 查询配置列表
     */
    @ApiOperation(value = "查询配置")
    //@PreAuthorize("@ss.hasPermi('system:config:list')")
    @GetMapping("/get")
    public R get()
    {
        Config one = configService.getOne(Wrappers.lambdaQuery(Config.class).last("limit 1"), false);
        if(one == null){
            Config config = new Config();
            config.setCarFreeTime("30");
            config.setEmployeeFreeTime("30");
            config.setSpeedLimit("30");
            configService.save(config);
            return R.ok(config);
        }
        return R.ok(one);
    }

    /**
     * 导出配置列表
     */
    @ApiOperation(value = "修改配置")
    //@PreAuthorize("@ss.hasPermi('system:config:edit')")
    @PostMapping("/update")
    public R update(HttpServletResponse response,@RequestBody Config config)
    {
        boolean update = configService.update(Wrappers.lambdaUpdate(Config.class)
                .isNotNull(Config::getId)
                .set(Config::getEmployeeFreeTime, config.getEmployeeFreeTime())
                .set(Config::getCarFreeTime, config.getCarFreeTime())
                .set(Config::getSpeedLimit, config.getSpeedLimit()));
        return R.ok(update);
    }
}
